﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CoyoEden.Web.Controls;
using CoyoEden.Models;
using CoyoEden;
using System.IO;

public partial class Views_CommunityList : ViewBase
{
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!Page.IsPostBack && !Page.IsCallback) {
			string theme = PortalSettings.Instance.Theme;
			if (Request.QueryString["theme"] != null)
				theme = Request.QueryString["theme"];

			string path = Utils.RelativeWebRoot + "themes/" + theme + "/CommunityView.ascx";//theme's ascx
			if (!File.Exists(Request.MapPath(path))) {
				path = Utils.RelativeWebRoot + "Views/CommunityView.ascx";//default ascx
			}
			if (Community.Communities.Count == 0) {
				phCommunities.Controls.Add(new LiteralControl("<h3>目前还没有任何社区！</h3>"));
				return;
			}
			//Add community
			Community.Communities.ForEach(c => {
				CommunityViewBase control = (CommunityViewBase)LoadControl(path);
				control.TheCommunity = c;
				phCommunities.Controls.Add(control);
			});
		}//endof !Page.IsPostBack&&!Page.IsCallBack
	}
}
